package com.example.day10_zuoye.fragmnet;


import android.os.Bundle;

import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.day10_zuoye.R;
import com.example.day10_zuoye.adapter.MyTabPagerAdapter;
import com.google.android.material.tabs.TabLayout;

import java.util.ArrayList;
import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 */
public class OneFragment extends Fragment {
    private TabLayout tabLayout;
    private ViewPager viewPager;
    private List<Fragment> list;
    private List<String> title;
    private MyTabPagerAdapter myTabPagerAdapter;


    public OneFragment() {

    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_one, container, false);
        viewPager = view.findViewById(R.id.view_pager);
        tabLayout = view.findViewById(R.id.tab);

        list = new ArrayList<>();
        list.add(new OneFragmentOne());
        list.add(new OneFragmentOne());
        list.add(new OneFragmentOne());
        title = new ArrayList<>();
        title.add("111");
        title.add("111");
        title.add("111");

        myTabPagerAdapter = new MyTabPagerAdapter(getChildFragmentManager(),list,title);
        viewPager.setAdapter(myTabPagerAdapter);

        tabLayout.setupWithViewPager(viewPager);


        return view;
    }

}
